import { sysTenant } from '/@/api/baas/model/sysTenantModel';
import { sysTenantGetApi } from '/@/api/baas/sysTenant';
import { defineStore } from 'pinia';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface TenantState {
  tenant: Nullable<sysTenant>;
  list: Nullable<sysTenant>[];
}

export const useTenantStore = defineStore({
  id: 'app-tanant',
  state: (): TenantState => ({
    tenant: null,
    list: [],
  }),
  getters: {
    getTenant(state): sysTenant {
      return state.tenant | null;
    },
    getList(state): sysTenant[] {
      return state.list | null;
    },
  },
  actions: {
    setTenant(t: sysTenant) {
      this.tenant = t;
    },
    setList(t: sysTenant[]) {
      this.list = t;
    },
    resetState() {
      this.tenant = null;
      this.list = [];
    },
    async getTenantById(id: number): Promise<sysTenant> {
      const data = await sysTenantGetApi(id);
      this.setTenant(data);
      return data;
    },
  },
});
